#include <iostream>
#include <vector>
using namespace std;

class Board {
public:
    static bool checkWon(vector<vector<int>>& board)
    {
        // write code here
        int n = board.size();

        for (int i = 0; i < n; i++)
        {
            if (board[i][0] == 1)
            {
                int count = 0;
                for (int k = 0; k < n; k++)
                {
                    if (board[i][k] == 1) count++;
                    else break;
                }

                if (count == n) return true;
            }
        }

        for (int i = 0; i < n; i++)
        {
            if (board[0][i] == 1)
            {
                int count = 0;
                for (int k = 0; k < n; k++)
                {
                    if (board[k][i] == 1) count++;
                    else break;
                }

                if (count == n) return true;
            }
        }

        int count = 0;
        for (int i = 0, j = 0; i < n; i++, j++)
        {
            if (board[i][j] == 1) count++;
            else break;
        }

        if (count == n) return true;

        count = 0;
        for (int i = 0, j = n - 1; i < n; i++, j--)
        {
            if (board[i][j] == 1) count++;
            else break;
        }

        if (count == n) return true;

        return false;
    }
};

int main()
{
    vector<vector<int>> board(3,vector<int>(3));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> board[i][j];
        }
    }

    cout << Board::checkWon(board);

    return 0;
}